<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
    // 用call实现继承
      // 定义父类
      function Person(name, sex) {
        this.name = name;
        this.sex = sex;
        this.eat = function () {
          return this.name + "最爱吃水果";
        };
      }
      Person.prototype.addr = "河南";//构造继承，不能继承原型
      //  定义子类
      function Student(name, sex, age) {
        // 继承父类Person
        Person.call(this, name, sex);
        // 子类拥有自己的属性和方法
        this.age = age;
        this.study = function (course) {
          return this.name + "最爱学" + course;
        };
      }
      // Person.qq = "123444"; 继承相当于是复制，父类再添加属性/方法，将不会追加到子类
      //  实例化子类
      var stu1 = new Student("王大头", "女", 18);
      console.log(stu1);
      console.log(stu1.eat());
      console.log(stu1.study("前端开发"));

    // 用apply实现继承
      // 定义父类
     /*  function Person(name, sex) {
        this.name = name;
        this.sex = sex;
        this.eat = function () {
          return this.name + "最爱吃水果";
        };
      }
      //  定义子类
      function Student(name, sex, age) {
        // 继承父类Person
        Person.apply(this, [name, sex]);
        // 子类拥有自己的属性和方法
        this.age = age;
        this.study = function (course) {
          return this.name + "最爱学" + course;
        };
      }
      //  实例化子类
      var stu1 = new Student("王大头", "女", 18);
      console.log(stu1);
      console.log(stu1.eat());
      console.log(stu1.study("前端开发")); */
    </script>
  </body>
</html>
